/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.gruposicom.view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author marcelo
 */
public class TableFormat extends DefaultTableCellRenderer
{    
    Font normal = new Font( "Arial",Font.PLAIN,12 );
    Font negrilla = new Font( "Helvetica",Font.BOLD,18 );
    Font cursiva = new Font( "Times new roman",Font.ITALIC,12 );

    @Override 
    public Component getTableCellRendererComponent (JTable table, Object value, boolean selected, boolean focused, int row, int column ) 
    {
        setEnabled(table == null || table.isEnabled()); 
        
//        setBackground(Color.cyan);//color de fondo
//        table.setFont(normal);//tipo de fuente
//        table.setForeground(Color.black);//color de texto
//        setHorizontalAlignment(2);//derecha
                
        //si la politica se esta evaluando el fondo debe ser amarillo
        if(String.valueOf(table.getValueAt(row,column)).equals("ANALIZANDO"))
	{            
//            table.setValueAt("<vacio>", row, column);
            setBackground(Color.yellow);                         
            table.setForeground(Color.black);
            table.setFont(cursiva);
        }
        
        //Si el analisis de la politica resulto positivo
        if(String.valueOf(table.getValueAt(row,column)).equals("CORRECTO"))
        {
            setBackground(Color.green); 
            table.setForeground(Color.black);
            setHorizontalAlignment(0);//centro
        }                        
        
        //si el analisis de la politica resulto negativo
        if(String.valueOf(table.getValueAt(row,column)).equals("ERROR"))
        {
            setBackground(Color.red);         
            setHorizontalAlignment(0);//centro
            table.setForeground(Color.white);
        }
//         /*--------*/   
//        if(String.valueOf(table.getValueAt(row,column)).equals("Bolivia")){
//            setBackground(Color.GREEN); 
//            table.setFont(negrilla);                
//            setHorizontalAlignment(0);//centro
//        }        
//        /*--------*/
//        //si la celda contiene números
//        if(isNumber(String.valueOf(table.getValueAt(row,column)))){
//            setBackground(Color.BLUE); 
//            setHorizontalAlignment(4);//izquierda
//        }      
        
        super.getTableCellRendererComponent(table, value, selected, focused, row, column);         
        return this;
 }
    
 //
 private boolean isNumber(String cadena){
         try {
             Double.parseDouble(cadena.replace(",", ""));
         } catch (NumberFormatException nfe){
             String newCadena = cadena.replace(".", "").replace(',', '.');
             try{
                 Double.parseDouble(newCadena);
             } catch (NumberFormatException nfe2){
                 return false;
             }
        }
         return true;
    }

}